package com.martin.lib_base.ktx

/**
 * 按照数量进行分组
 */
fun <T> List<T>.groupByQuantity(quantity: Int): List<List<T>> {
    val result = arrayListOf<List<T>>()
    val count = this.size / quantity + (if (this.size % quantity > 0) 1 else 0)
    for (i in 0 until count) {
        val start = i * quantity
        val end = if (i == count - 1) this.size else (i + 1) * quantity
        result.add(this.subList(start, end))
    }
    return result
}